import {reactive, ref} from "vue";
import {getDeptList} from "@/api/system/dept";
import {searchForm} from "@/views/system/dept/hooks/useSearch";
import _ from "lodash"
import useBuildTreeSelectOptions from "@/hooks/useBuildTreeSelectOptions/useBuildTreeSeclectOptions";
export interface Dept{
    id: number;
    name: string;
    parentId: number;
    sort: number;
    createTime: string;
    updateTime: string;
}
const table = reactive<{tableData: Dept[]}>({
    tableData:[]
})
const {treeSelectOptions,buildTreeSelectOptions}=useBuildTreeSelectOptions()
const loading = ref<boolean>(false)
function getDataList() {
    loading.value = true
    getDeptList({
        deptName:searchForm.deptName,
        dataStatus:searchForm.dataStatus
    }).then(res=>{
        table.tableData = (res.data as Dept[])
        buildTreeSelectOptions(_.cloneDeep(res.data),'id',"name")
        loading.value = false
    })
}
function useTable () {
    return {
        treeSelectOptions,
        table,
        getDataList,
        loading
    }
}
export default useTable
